package com.ibeifeng.jasperreport;

import java.util.HashMap;

import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;

public class DemoJasperReport02_Jasper {

	public static void main(String[] args) {
		//声明JasperReport
		JasperReport jasperReport = null;
		//声明JasperPrint
		JasperPrint jasperPrint = null;
		//指定*.jasper文件的路径和名称
		String jasperFileName = "reports/report01.jasper";
		
		try {
			//载入报表模板文件
			jasperReport = (JasperReport)JRLoader.loadObjectFromFile(jasperFileName);
			
			//填充报表
			jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap<String,Object>(), new JREmptyDataSource());
			
			//导出PDF文件
			JasperExportManager.exportReportToPdfFile(jasperPrint,"jasperreport02.pdf");
		} catch (JRException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
